﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for Util
/// </summary>
public class Util
{
	public Util()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public static string CultureName = "en-US";

    public static bool IsBlank(String str)
    {
        if (str == null) return true;
        return str.Length == 0;
    }

    public static bool IsInputBlank(String str)
    {
        if (IsBlank(str)) return true;
        return str.Replace("\"", "").Length == 0;
    }

    public static DateTime? StringToDate(String dateStr)
    {
        if (IsBlank(dateStr)) return null;

        DateTime MyDateTime = DateTime.ParseExact(dateStr, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);
        return MyDateTime;
    }


    public static bool checkAllBlankInput(string[] inputs)
    {
        foreach (string input in inputs)
        {
            if (input != "") return false;
        }

        return true;
    }

    public static bool checkAllNotBlankInput(string[] inputs)
    {
        foreach (string input in inputs)
        {
            if (input == "") return false;
        }

        return true;
    }


    public static int getAge(DateTime dob)
    {
        DateTime zeroTime = new DateTime(1, 1, 1);
        TimeSpan span = DateTime.Now - dob;

        // because we start at year 1 for the Gregorian 
        // calendar, we must subtract a year here.
        int age = (zeroTime + span).Year - 1;

        return age;
    }

    public static int getAge(DateTime? dob)
    {
        if (dob == null) return -1;
        return getAge((DateTime)dob);
    }

    public static bool isValueNotNull(Dictionary<string, Object> applicationInfo, string key)
    {
        bool isValueNotNull = false;

        if (applicationInfo == null) return isValueNotNull;

        if (applicationInfo.ContainsKey(key) && applicationInfo[key] != null)
        {
            isValueNotNull = true;
        }
        else
        {
            isValueNotNull = false;
        }

        return isValueNotNull;
    }
}